﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeoVision.Addin.Core.ShapeCore;

namespace GeoVision.Addin.Core.Spatial
{
    public static class ShapeFileGeoGenerator
    {
        public static GeoShape ConvertShapeFileRecordToGeoShape(ShapeFileRecord record)
        {
            GeoShape _shape = new GeoShape();

            for (int i = 0; i < record.NumberOfParts; i++)
            {

                GeoShapeSegment segment = new GeoShapeSegment();

                int start = record.Parts[i];
                int end;
                if (record.NumberOfParts > 1 && i != (record.NumberOfParts - 1))
                    end = record.Parts[i + 1];
                else
                    end = record.NumberOfPoints;

                for (int j = start; j < end; j++)
                {
                    GeoPoint pt = new GeoPoint(record.Points[j]);

                    segment.Points.Add(pt);
                }
                _shape.Segments.Add(segment);
            }
            

            return _shape;
        }
    }
}
